<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
use Illuminate\Http\Request;


Route::get('/', function () {
    return view('welcome');
});


Route::get('/index', function () {
    return redirect('jushi_admin/index.html');
});

Route::get('/user/auth', function (\Illuminate\Http\Request $request) {
    dump($request);
});

Route::get('/redirect', function (\Illuminate\Http\Request $request) {
    $input = $request->all();
    $query = http_build_query([
        'client_id' => $input['client_id'],
//        'redirect_uri' => ' https://device.rangstone.com/callback',
        'redirect_uri' => 'https://open.bot.tmall.com/oauth/callback?skillId=5397&token=MzU1ODc1NjI1QUZFSElORkRWUQ==',
//        'redirect_uri' => urldecode($input['redirect_uri']),
        'response_type' => 'code',
        'scope' => '',
    ]);

    return redirect('https://device.rangstone.com/oauth/authorize?'.$query);
});

Auth::routes();

Route::get('/home', 'HomeController@index')->name('home');

Route::get('/callback', function (Request $request){
    $http= new GuzzleHttp\Client;

    $response = $http->post('https://device.rangstone.com/oauth/token',[
        'form_params' => [
            'grant_type' => 'authorization_code',
            'client_id' => 3 ,
            'client_secret' => 'zl9oJO16EnpCsp473qWBrSyZXfL6kKL5AlzuozSg' ,
            'redirect_uri' => 'https://open.bot.tmall.com/oauth/callback',
            'code' => $request->code,
        ],
    ]);

    return json_decode((string) $response->getBody(), true);
});



